package com.lagou.homework.game

import scala.io.StdIn

object PlayGame {
  def main(args: Array[String]): Unit = {
    var computer: Int = 0;
    var user: String = "";
    var uIndex: Int = 0
    var flag = true
    val game = new Game
    //初始化游戏
    game.init();
    println("	   *********************")
    println("	       **猜拳，开始**")
    println("	   *********************")

    println("请输入玩家名称:")
    user = StdIn.readLine()
    game.chooseUser(user)

    println("请选择对战角色:(1.刘备 2.关羽 3.张飞)")
    computer = StdIn.readInt()
    if (computer == 1) {
      println("你选择了与刘备对战")
    } else if (computer == 2) {
      println("你选择了与关羽对战")
    } else if (computer == 3) {
      println("你选择了与张飞对战")
    } else {
      println("输入错误，默认与刘备对战")
      computer = 1;
    }
    game.chooseComputer(computer)

    while (flag) {
      println("请出拳！1.剪刀 2.石头 3.布")
      uIndex = StdIn.readInt()
      if (uIndex < 1 || uIndex > 3) {
        println("输入不符合规范，默认出剪刀！")
        uIndex = 1
      }

      game.play(uIndex)

      println("是否开启下一轮(y/n)")
      val choose = StdIn.readLine()
      if (choose == "n") {
        flag = false
        println("退出游戏！")
        println("---------------------------------------")
        game.result()
      }
    }
  }
}